package com.xhwl.logistics.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

/**
 * @description: 线程池配置
 * @author: lu.Aaron
 * @create: 2021-08-16 14:59
 **/

@Configuration
@ComponentScan("com.xhwl.logistics.service.impl")
@EnableAsync
public class ThreadPoolConfig {
    @Bean
    public Executor taskExecutor(){
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        //设置核心线程数
        executor.setCorePoolSize(10);
        //设置最大线程数
        executor.setMaxPoolSize(20);
        //线程池所使用的缓冲队列
        executor.setQueueCapacity(250);
        //设置线程名
        executor.setThreadNamePrefix("cent-logistics");
        //设置多余线程等待的时间，单位：秒
        executor.setKeepAliveSeconds(60);
        // 初始化线程
        executor.initialize();
        return executor;
    }
}

